package com.mandroid.forecast.business;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;

import com.mandroid.forecast.util.Utils;

public class Weather {
	
	private String city;
	
	private String region;
	
	private String country;
	
	private String temperatureUnit;
	
	private String distanceUnit;
	
	private String pressureUnit;
	
	private String speedUnit;
	
	private String humidity;
	
	private String visibility;
	
	private String pressure;
	
	private String sunrise;
	
	private String sunset;
	
	private String text;
	
	private String code;
	
	private String date;
	
	private String day;
	
	private String forecastDate;
	
	private String forecastDay;

	private String high;
	
	private String low;
	
	private String forecastText;
	
	private String forecastCode;
	
	private String forecastHigh;
	
	private String forecastLow;
	
	
	public String getForecastDate() {
		return forecastDate;
	}

	public void setForecastDate(String forecastDate) {
		this.forecastDate = forecastDate;
	}

	public String getForecastDay() {
		return forecastDay;
	}

	public void setForecastDay(String forecastDay) {
		this.forecastDay = forecastDay;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getTemperatureUnit() {
		return temperatureUnit;
	}

	public void setTemperatureUnit(String temperatureUnit) {
		this.temperatureUnit = temperatureUnit;
	}

	public String getDistanceUnit() {
		return distanceUnit;
	}

	public void setDistanceUnit(String distanceUnit) {
		this.distanceUnit = distanceUnit;
	}

	public String getPressureUnit() {
		return pressureUnit;
	}

	public void setPressureUnit(String pressureUnit) {
		this.pressureUnit = pressureUnit;
	}

	public String getSpeedUnit() {
		return speedUnit;
	}

	public void setSpeedUnit(String speedUnit) {
		this.speedUnit = speedUnit;
	}

	public String getHumidity() {
		return humidity;
	}

	public void setHumidity(String humidity) {
		this.humidity = humidity;
	}

	public String getVisibility() {
		return visibility;
	}

	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}

	public String getPressure() {
		return pressure;
	}

	public void setPressure(String pressure) {
		this.pressure = pressure;
	}

	public String getSunrise() {
		return sunrise;
	}

	public void setSunrise(String sunrise) {
		this.sunrise = sunrise;
	}

	public String getSunset() {
		return sunset;
	}

	public void setSunset(String sunset) {
		this.sunset = sunset;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getHigh() {
		return high;
	}

	public void setHigh(String high) {
		this.high = high;
	}

	public String getLow() {
		return low;
	}

	public void setLow(String low) {
		this.low = low;
	}

	public String getForecastText() {
		return forecastText;
	}

	public void setForecastText(String forecastText) {
		this.forecastText = forecastText;
	}

	public String getForecastCode() {
		return forecastCode;
	}

	public void setForecastCode(String forecastCode) {
		this.forecastCode = forecastCode;
	}

	public String getForecastHigh() {
		return forecastHigh;
	}

	public void setForecastHigh(String forecastHigh) {
		this.forecastHigh = forecastHigh;
	}

	public String getForecastLow() {
		return forecastLow;
	}

	public void setForecastLow(String forecastLow) {
		this.forecastLow = forecastLow;
	}
	
	//Business Related Method
	public String getLocationText(){
		StringBuilder locationText = new StringBuilder();
		locationText.append(city).append(", ");
		if (!Utils.isNullOrEmpty(region)){
			locationText.append(region).append(", ");
		}
		locationText.append(country);
		return locationText.toString();
	}
	
	public String getHighText() {
		StringBuilder highText = null;
		if (!Utils.isNullOrEmpty(high) && !Utils.isNullOrEmpty(this.temperatureUnit)) {
			highText = new StringBuilder("High: ");
			highText.append(high).append(temperatureUnit);
		}
		return highText == null ? null : highText.toString();
	}
	
	public String getLowText() {
		StringBuilder lowText = null;
		if (!Utils.isNullOrEmpty(low) && !Utils.isNullOrEmpty(this.temperatureUnit)) {
			lowText = new StringBuilder("Low: ");
			lowText.append(low).append(temperatureUnit);
		}
		return lowText == null ? null : lowText.toString();
	}
	
	public String getForecastHighText() {
		StringBuilder highText = null;
		if (!Utils.isNullOrEmpty(this.forecastHigh) && !Utils.isNullOrEmpty(this.temperatureUnit)) {
			highText = new StringBuilder("High: ");
			highText.append(forecastHigh).append(temperatureUnit);
		}
		return highText == null ? null : highText.toString();
	}
	
	public String getForecastLowText() {
		StringBuilder lowText = null;
		if (!Utils.isNullOrEmpty(this.forecastLow) && !Utils.isNullOrEmpty(this.temperatureUnit)) {
			lowText = new StringBuilder("Low: ");
			lowText.append(forecastLow).append(temperatureUnit);
		}
		return lowText == null ? null : lowText.toString();
	}
	
	public String getPressureText() {
		StringBuilder pressureText = null; 
		if (!Utils.isNullOrEmpty(this.pressure) && !Utils.isNullOrEmpty(this.pressureUnit)) {
			pressureText = new StringBuilder("Pressure: ");
			pressureText.append(pressure).append(pressureUnit);
		}
		return pressureText == null ? null : pressureText.toString();
	}
	
	public String getHumidityText() {
		StringBuilder humidityText = null; 
		if (!Utils.isNullOrEmpty(this.humidity)) {
			humidityText = new StringBuilder("Humidity: ");
			humidityText.append(humidity).append("%25");
		}
		return humidityText == null ? null : humidityText.toString();
	}
	
	public String getVisibilityText() { 
		StringBuilder visibilityText = null;
		if (!Utils.isNullOrEmpty(this.visibility) && !Utils.isNullOrEmpty(this.distanceUnit)) {
			visibilityText = new StringBuilder("Visibility: ");
			visibilityText.append(visibility).append(distanceUnit);
		}
		return visibilityText == null ? null : visibilityText.toString();
	}
	
	public String getDateText(){
		StringBuilder dateText = null;
		if (!Utils.isNullOrEmpty(this.date) && !Utils.isNullOrEmpty(this.day)) {
			dateText = new StringBuilder();
			dateText.append(day).append(", ").append(date);
		}
		return dateText == null ? null : dateText.toString();
	}
	
	public String getForecastDateText(){
		StringBuilder dateText = null;
		if (!Utils.isNullOrEmpty(this.forecastDate) && !Utils.isNullOrEmpty(this.forecastDay)) {
			dateText = new StringBuilder();
			dateText.append(forecastDay).append(", ").append(forecastDate);
		}
		return dateText == null ? null : dateText.toString();
	}
	
	public String getConditionText() {
		StringBuilder conditionText = new StringBuilder("Condition: ");
		conditionText.append(this.text);
		return conditionText.toString();
	}
	
	public String getSunriseText() {
		StringBuilder sunriseText = new StringBuilder("Sunrise: ");
		sunriseText.append(sunrise);
		return sunriseText.toString();	
	}
	
	public String getSunsetText() {
		StringBuilder sunsetText = new StringBuilder("Sunset: ");
		sunsetText.append(sunset);
		return sunsetText.toString();
	}
	
	public String getForecastConditionText() {
		StringBuilder conditionText = new StringBuilder("Condition: ");
		conditionText.append(this.text);
		return conditionText.toString();
	}
	
	public String getContent(){
		StringBuffer result = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
		result.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
		result.append("<head>");
		result.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
		result.append("<title>Weather</title>");
		result.append("</head><body><table style=\"font-size:15px\">");
		result.append("<tr style=\"color:green;font-weight:bold;\"><td colspan=\"2\">");
		result.append(this.getLocationText()).append("</td></tr>");
		result.append("<tr style=\"font-weight:bold;font-weight: bold;color: #666666;font-style:italic;\"><td colspan=\"2\">");
		result.append(this.getDateText()).append("</td></tr>");
		result.append("<tr><td colspan=\"2\">");
		result.append(this.getConditionText()).append("</td></tr>");
		result.append("<tr><td>").append(this.getHighText()).append("</td>");
		result.append("<td>").append(this.getLowText()).append("</td></tr>");
		result.append("<tr><td>").append(this.getPressureText()).append("</td>");
		result.append("<td>").append(this.getHumidityText()).append("</td></tr>");
		result.append("<tr><td>").append(this.getSunriseText()).append("</td>");
		result.append("<td>").append(this.getSunsetText()).append("</td></tr>");
		result.append("<tr><td colspan=\"2\">");
		result.append(this.getVisibilityText()).append("</td></tr>");
		result.append("<tr style=\"font-weight:bold;font-weight: bold;color: #666666;font-style:italic;\"><td colspan=\"2\">");
		result.append(this.getForecastDateText()).append("</td></tr>");
		result.append("<tr><td colspan=\"2\">");
		result.append(this.getForecastConditionText()).append("</td></tr>");
		result.append("<tr><td>").append(this.getForecastHighText()).append("</td>");
		result.append("<td>").append(this.getForecastLowText()).append("</td></tr>");
		result.append("</table></body></html>");
		return result.toString();
	}
}
